/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.shop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.shop.entity.shop.HkEnterShopInfo;
import com.thinkgem.jeesite.modules.hk.shop.service.shop.HkEnterShopInfoService;

/**
 * 店铺身份信息Controller
 * @author 李欣荣
 * @version 2018-10-09
 */
@Controller

@RequestMapping(value = "${adminPath}/shop/shop/hkEnterShopInfo")
public class HkEnterShopInfoController extends BaseController {

	@Autowired
	private HkEnterShopInfoService hkEnterShopInfoService;
	
	@ModelAttribute
	public HkEnterShopInfo get(@RequestParam(required=false) String id) {
		HkEnterShopInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkEnterShopInfoService.get(id);
		}
		if (entity == null){
			entity = new HkEnterShopInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:shop:hkEnterShopInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkEnterShopInfo hkEnterShopInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkEnterShopInfo> page = hkEnterShopInfoService.findPage(new Page<HkEnterShopInfo>(request, response), hkEnterShopInfo); 
		model.addAttribute("page", page);
		return "hk/shop/shop/hkEnterShopInfoList";
	}

	@RequiresPermissions("shop:shop:hkEnterShopInfo:view")
	@RequestMapping(value = "form")
	public String form(HkEnterShopInfo hkEnterShopInfo, Model model) {
		model.addAttribute("hkEnterShopInfo", hkEnterShopInfo);
		return "hk/shop/shop/hkEnterShopInfoForm";
	}

	@RequiresPermissions("shop:shop:hkEnterShopInfo:edit")
	@RequestMapping(value = "save")
	public String save(HkEnterShopInfo hkEnterShopInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkEnterShopInfo)){
			return form(hkEnterShopInfo, model);
		}
		hkEnterShopInfoService.save(hkEnterShopInfo);
		addMessage(redirectAttributes, "保存店铺身份信息成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkEnterShopInfo/?repage";
	}
	
	@RequiresPermissions("shop:shop:hkEnterShopInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(HkEnterShopInfo hkEnterShopInfo, RedirectAttributes redirectAttributes) {
		hkEnterShopInfoService.delete(hkEnterShopInfo);
		addMessage(redirectAttributes, "删除店铺身份信息成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkEnterShopInfo/?repage";
	}

}